//
//  LGConsultHomeController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/21.
//  在线咨询

#import "LGConsultHomeController.h"
//搜索患者
#import "LGPatientSearchController.h"

//选择医生群聊弹框
#import "LGSelectGroupChatView.h"

#import "LGConsultHomeViewCell.h"
#import "LGBottomShadowView.h"


#import "TUICore.h"
#import "TUIConversationListDataProvider.h"
#import "TUIConversationListBaseDataProvider.h"
#import "TUIConversationListControllerListener.h"
#import "TUIConversationCellData.h"
#import <ImSDK_Plus/V2TIMManager.h>
#import "TUIMessageDataProvider.h"
//测试
#import "LGGroupChatMemberController.h"
#import "TUILogin.h"
#import "TUICallKit.h"
#import "TUIConversationListController.h"
#import "TUIC2CChatViewController.h"
#import "TUIGroupChatViewController.h"
#import "LGRecommendDoctorController.h"
#import "LGRecommendServiceController.h"
#import "LGECGDetailViewController.h"
@interface LGConsultHomeController ()<UITableViewDelegate,UITableViewDataSource,LGSelectGroupChatDelegate,TUIConversationListDataProviderDelegate>
/**   */
@property (nonatomic , strong)CAGradientLayer *gradientLayer;
/**   */
@property (nonatomic , strong)UIImageView *bgImageView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIButton *messageBtn;
/**   */
@property (nonatomic , strong)UIButton *searchBtn;
/**   */
@property (nonatomic , strong)UIImageView *extendView;
/**   */
@property (nonatomic , strong)UIView *cornerView;
/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)LGSelectGroupChatView *groupView;
/**   */
@property (nonatomic , strong)LGBottomShadowView *shadowView;

@property (nonatomic, weak) id<TUIConversationListControllerListener> delegate;

@property (nonatomic, strong) TUIConversationListBaseDataProvider *dataProvider;
/**   */
@property (nonatomic , strong)NSDictionary *dataDic;
/**   */
@property (nonatomic , strong)NSArray *dataArray;
/**   */
@property (nonatomic , copy)NSString *systemId;

@end

@implementation LGConsultHomeController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createSubView];
    [self.dataProvider loadNexPageConversations];
    [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(onFriendInfoChanged:) name:@"FriendInfoChangedNotification" object:nil];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self viewWillAppearAction];
}

//登录腾讯云、刷新数据
-(void)viewWillAppearAction{
    LGLogFunction;
    [self requestData];
    [self.dataProvider loadNexPageConversations];
    V2TIMLoginStatus loginStatus = [[V2TIMManager sharedInstance] getLoginStatus];
    if(loginStatus == V2TIM_STATUS_LOGOUT){
        [LGLoginManager loginTencentCloud];
    }
}

//请求数据
-(void)requestData{
    [RequestUtil withPOST:@"/doctor/workbench/index" parameters:@{} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if(code == 200){
            self.dataDic = returnData;
            NSString *roleType = LGNSString(returnData[@"doctor"][@"role_type_val"]);
            [[NSUserDefaults standardUserDefaults] setValue:roleType forKey:@"roleId"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无会话" offset:30];
        }
    } error:^(NSError *error) {
        self.isfirst = NO;
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无会话" offset:30];
        }
        [self.emptyView stopBufferAction];
    }];
}

- (void)onFriendInfoChanged:(NSNotification *)notice{
    V2TIMFriendInfo *friendInfo = notice.object;
    if (friendInfo == nil) {
        return;
    }
    for (TUIConversationCellData *cellData in self.dataProvider.conversationList) {
        if ([cellData.userID isEqualToString:friendInfo.userID]) {
            NSString *title = friendInfo.friendRemark;
            if (title.length == 0) {
                title = friendInfo.userFullInfo.nickName;
            }
            if (title.length == 0) {
                title = friendInfo.userID;
            }
            cellData.title = title;
            [self.tableView reloadData];
            break;
        }
    }
}

-(void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    if(dataArray.count == 0){
        [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无数据" offset:50];
    }else{
        [self.emptyView stopBufferAction];
    }
}


//搜索患者
-(void)searchBtnAction{
    LGPatientSearchController *controller = [[LGPatientSearchController alloc]init];
    [self.navigationController pushViewController:controller animated:YES];
}

//扩展按钮
-(void)messageBtnAction{
    self.extendView.hidden = NO;
}

//发起群聊 、 一键已读
-(void)selectExtendAction:(UITapGestureRecognizer *)sender{
    CGPoint point = [sender locationInView:self.extendView];
    if (point.y <= viewPix(80)) {
        //发起群聊 - 医生团队间的聊天
        [self.groupView showViewAniamtion];
        
    }else{
        //一键已读
        NSMutableArray *idArray = [NSMutableArray array];
        for (TUIConversationCellData *data in self.dataArray) {
            NSString *userID = data.userID;
            if (userID.length > 0) {
                [TUIMessageDataProvider markC2CMessageAsRead:userID succ:nil fail:nil];
            }
            NSString *groupID = data.groupID;
            if (groupID.length > 0) {
                [TUIMessageDataProvider markGroupMessageAsRead:groupID succ:nil fail:nil];
            }
        }
//        [TUIMessageDataProvider markConversationAsUndead:idArray enableMark:NO];
        [self.dataProvider loadNexPageConversations];
        [self handleConsultData];
    }
    self.extendView.hidden = YES;
}

-(void)consultBtnAction:(UIButton *)sender{
    TUIChatConversationModel *model = [[TUIChatConversationModel alloc]init];
    model.groupID = @"@TGS#1CAMIMMMA";
    TUIGroupChatViewController *controller = [[TUIGroupChatViewController alloc]init];
    controller.needCustomeData = NO;
    [controller setConversationData:model];
    [self.navigationController pushViewController:controller animated:YES];
}

//医生群聊
-(void)enterTheGroupChatRoom:(NSString *)groupId title:(NSString *)title{
    TUIChatConversationModel *model = [[TUIChatConversationModel alloc]init];
    model.groupID = groupId;
    model.title = title;
    TUIGroupChatViewController *controller = [[TUIGroupChatViewController alloc]init];
    controller.needCustomeData = NO;
    [controller setConversationData:model];
    [self.navigationController pushViewController:controller animated:YES];
}


#pragma mark TUIConversationListDataProviderDelegate
- (NSString *)getConversationDisplayString:(V2TIMConversation *)conversation{
    V2TIMMessage *msg = conversation.lastMessage;
    if (msg.customElem == nil || msg.customElem.data == nil) {
        return nil;
    }
    NSDictionary *param = [TUITool jsonData2Dictionary:msg.customElem.data];
    if (param != nil && [param isKindOfClass:[NSDictionary class]]) {
        NSString *businessID = param[@"businessID"];
        if (![businessID isKindOfClass:[NSString class]]) {
            return nil;
        }

        // whether custom jump message
        if ([businessID isEqualToString:BussinessID_TextLink] || ([(NSString *)param[@"text"] length] > 0 && [(NSString *)param[@"link"] length] > 0)) {
            NSString *desc = param[@"text"];
            if (msg.status == V2TIM_MSG_STATUS_LOCAL_REVOKED) {
                if(msg.isSelf){
                    desc = TUIKitLocalizableString(TUIKitMessageTipsYouRecallMessage);
                } else if (msg.userID.length > 0){
                    desc = TUIKitLocalizableString(TUIkitMessageTipsOthersRecallMessage);
                } else if (msg.groupID.length > 0) {
                    /**
                     * 对于群组消息的名称显示，优先显示群名片，昵称优先级其次，用户ID优先级最低。
                     * For the name display of group messages, the group business card is displayed first, the nickname has the second priority, and the user ID has the lowest priority.
                     */
                    NSString *userName = msg.nameCard;
                    if (userName.length == 0) {
                        userName = msg.nickName?:msg.sender;
                    }
                    desc = [NSString stringWithFormat:TUIKitLocalizableString(TUIKitMessageTipsRecallMessageFormat), userName];
                }
            }
            return desc;
        }else if([businessID isEqualToString:BussinessID_GroupCreate] || [param.allKeys containsObject:BussinessID_GroupCreate]) {
            // whether the tips message of creating group
            return [NSString stringWithFormat:@"\"%@\"%@",param[@"opUser"],param[@"content"]];
        }
    }
    return nil;
}

- (void)insertConversationsAtIndexPaths:(NSArray *)indexPaths {
    LGLogFunction;
    if (!NSThread.isMainThread) {
        __weak typeof(self) weakSelf = self;
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf insertConversationsAtIndexPaths:indexPaths];
        });
        return;
    }
    [self handleConsultData];
}

- (void)reloadConversationsAtIndexPaths:(NSArray *)indexPaths {
    if (!NSThread.isMainThread) {
        __weak typeof(self) weakSelf = self;
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf reloadConversationsAtIndexPaths:indexPaths];
        });
        return;
    }
    if (self.tableView.isEditing) {
        self.tableView.editing = NO;
    }
    [self handleConsultData];
}

- (void)deleteConversationAtIndexPaths:(NSArray *)indexPaths {
    if (!NSThread.isMainThread) {
        __weak typeof(self) weakSelf = self;
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf deleteConversationAtIndexPaths:indexPaths];
        });
        return;
    }
    [self handleConsultData];
}

- (void)reloadAllConversations{
    if (!NSThread.isMainThread) {
        __weak typeof(self) weakSelf = self;
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf reloadAllConversations];
        });
        return;
    }
    [self handleConsultData];
}

-(void)handleConsultData{
    NSArray *tempArray = self.dataProvider.conversationList;
    NSMutableArray *dataArray = [NSMutableArray array];
    for (TUIConversationCellData *data in tempArray) {
        [dataArray addObject:data];
//        NSDictionary *customeDic = nil;
//        if(data.cloudCustomData){
//            customeDic = [NSJSONSerialization JSONObjectWithData:data.cloudCustomData options:NSJSONReadingMutableLeaves error:nil];
//        }
//        if(customeDic && [customeDic isKindOfClass:[NSDictionary class]] && [customeDic.allKeys count]>0 && [customeDic.allKeys containsObject:@"customMsg"]){
//            [dataArray addObject:data];
//        }
    }
    self.dataArray = [NSArray arrayWithArray:dataArray];
    [self.tableView reloadData];
}



#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LGConsultHomeViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    TUIConversationCellData *data = self.dataArray[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell fillWithData:data];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    TUIConversationCellData *data = [self.dataArray objectAtIndex:indexPath.row];
    NSDictionary *customeDic = nil;
    if(data.cloudCustomData){
        customeDic = [NSJSONSerialization JSONObjectWithData:data.cloudCustomData options:NSJSONReadingMutableLeaves error:nil];
    }
    if(customeDic && [customeDic isKindOfClass:[NSDictionary class]] && [customeDic.allKeys count]>0 && [customeDic.allKeys containsObject:@"customMsg"]){
        customeDic = [ObjectTool jsonToObject:customeDic[@"customMsg"]];
        NSString *doctorid = @"";
        NSString *appointId = @"";
        NSString *title = data.title;
        if(customeDic && [customeDic isKindOfClass:[NSDictionary class]] && [customeDic.allKeys count]>0){
            appointId = LGNSString(customeDic[@"appointment_id"]);
            title = LGNSString(customeDic[@"patient"][@"realname"]);
            doctorid = LGNSString(customeDic[@"doctor_id"]);
        }
        
        if(data.userID && data.userID.length>0){
            //单聊
            TUIChatConversationModel *model = [[TUIChatConversationModel alloc]init];
            model.title = title;
            model.userID = data.userID;
            TUIC2CChatViewController *controller = [[TUIC2CChatViewController alloc]init];
            controller.needCustomeData = YES;
            controller.doctorid = doctorid;
            controller.appointment_id = appointId;
            controller.roomKey = [NSString stringWithFormat:@"%@|||%@",XGUserId,model.userID];
            [controller setConversationData:model];
            [self.navigationController pushViewController:controller animated:YES];

        }else{
            //群聊
            TUIChatConversationModel *model = [[TUIChatConversationModel alloc]init];
            model.title = title;
            model.groupID = data.groupID;
            TUIGroupChatViewController *controller = [[TUIGroupChatViewController alloc]init];
            controller.needCustomeData = YES;
            controller.appointment_id = appointId;
            controller.roomKey = model.groupID;
            controller.doctorid = doctorid;
            [controller setConversationData:model];
            [self.navigationController pushViewController:controller animated:YES];
        }
        [self.delegate conversationListController:self didSelectConversation:data];
        
    }else if (data.userID && [data.userID isEqualToString:self.systemId]){
        //系统消息
        
    }else{
        NSDictionary *param = @{
            TUICore_TUIChatService_GetChatViewControllerMethod_TitleKey : data.title ?: @"",
            TUICore_TUIChatService_GetChatViewControllerMethod_UserIDKey : data.userID ?: @"",
            TUICore_TUIChatService_GetChatViewControllerMethod_GroupIDKey : data.groupID ?: @"",
            TUICore_TUIChatService_GetChatViewControllerMethod_AvatarImageKey : data.avatarImage ?: [UIImage new],
            TUICore_TUIChatService_GetChatViewControllerMethod_AvatarUrlKey : data.faceUrl ?: @"",
            TUICore_TUIChatService_GetChatViewControllerMethod_ConversationIDKey : data.conversationID ?: @"",
            TUICore_TUIChatService_GetChatViewControllerMethod_AtMsgSeqsKey : data.atMsgSeqs ?: @[],
            TUICore_TUIChatService_GetChatViewControllerMethod_DraftKey: data.draftText ?: @""
        };
        
        UIViewController *chatVC = (UIViewController *)[TUICore callService:TUICore_TUIChatService
                                                                     method:TUICore_TUIChatService_GetChatViewControllerMethod
                                                                      param:param];
        [self.navigationController pushViewController:(UIViewController *)chatVC animated:YES];
    }
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSMutableArray *rowActions = [NSMutableArray array];
    TUIConversationCellData *cellData = self.dataProvider.conversationList[indexPath.row];
    __weak typeof(self) weakSelf = self;
    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:TUIKitLocalizableString(Delete) handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        [weakSelf.dataProvider removeConversation:cellData];
    }];
    deleteAction.backgroundColor = RGB(242, 77, 76);
    [rowActions addObject:deleteAction];
    return rowActions;
}

// available ios 11 +
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) {
    __weak typeof(self) weakSelf = self;
    TUIConversationCellData *cellData = self.dataProvider.conversationList[indexPath.row];
    UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:TUIKitLocalizableString(Delete) handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
        completionHandler(YES);
        weakSelf.tableView.editing = NO;
        [weakSelf.dataProvider removeConversation:cellData];
    }];
    deleteAction.backgroundColor = RGB(242, 77, 76);
    UISwipeActionsConfiguration *configuration = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]];
    configuration.performsFirstActionWithFullSwipe = NO;
    return configuration;
}

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}

-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
    return UIModalPresentationNone;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    [self.dataProvider loadNexPageConversations];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    self.extendView.hidden = YES;
}

- (void)dealloc{
    [NSNotificationCenter.defaultCenter removeObserver:self];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.fd_prefersNavigationBarHidden = YES;
    self.gradientLayer.hidden = YES;
    [self.view addSubview:self.titleLabel];
    [self.view addSubview:self.searchBtn];
    [self.view addSubview:self.messageBtn];
    [self.view addSubview:self.cornerView];
    [self.cornerView addSubview:self.tableView];
    [self emptyViewWithSuperView:self.view frame:self.cornerView.frame];
    self.emptyView.cornerRidus = 15;
    self.emptyView.backgroundColor = [UIColor clearColor];
    [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无会话" offset:30];
    [self.view addSubview:self.extendView];
    [self.view addSubview:self.shadowView];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(viewPix(16));
        make.top.equalTo(self.view).offset(statusBarHeight+10);
        make.height.equalTo(@(25));
    }];
    [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.messageBtn.mas_left);
        make.centerY.equalTo(self.titleLabel);
        make.width.height.equalTo(@(viewPix(44)));
    }];
    [self.messageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).offset(-viewPix(6));
        make.centerY.width.height.equalTo(self.searchBtn);
    }];
    [self.extendView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.messageBtn.mas_bottom).offset(-viewPix(5));
        make.right.equalTo(self.view).offset(-viewPix(5));
        make.width.equalTo(@(viewPix(156)));
        make.height.equalTo(@(viewPix(160)));
    }];
    [[UIApplication sharedApplication].keyWindow addSubview:self.groupView];
}
//-(CAGradientLayer *)gradientLayer{
//    if(!_gradientLayer){
//        _gradientLayer = [CAGradientLayer layer];
//        _gradientLayer.frame = CGRectMake(0,statusBarHeight,Screen_W,viewPix(260));
//        _gradientLayer.startPoint = CGPointMake(0.5, 0);
//        _gradientLayer.endPoint = CGPointMake(0.5, 1);
//        _gradientLayer.colors = @[(__bridge id)[UIColor colorWithString:@"#FEFEFE"].CGColor, (__bridge id)[UIColor colorWithString:@"#F6F9FF"].CGColor, (__bridge id)[UIColor colorWithString:@"#E7EFFF"].CGColor, (__bridge id)[UIColor colorWithString:@"#FFFFFF"].CGColor, (__bridge id)[UIColor colorWithString:@"#FFFFFF" alpha:0].CGColor];
//        _gradientLayer.locations = @[@(0), @(0.1f), @(0.2f), @(0.8f), @(1.0f)];
//    }
//    return _gradientLayer;
//}
-(TUIConversationListBaseDataProvider *)dataProvider{
    if (!_dataProvider) {
        _dataProvider = [[TUIConversationListDataProvider alloc] init];
        _dataProvider.delegate = self;
    }
    return _dataProvider;
}

-(UIImageView *)bgImageView{
    if(!_bgImageView){
        _bgImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"首页-背景"]];
        _bgImageView.frame = CGRectMake(0, 0, Screen_W, viewPix(354));
    }
    return _bgImageView;
}


-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"在线咨询" colorString:@"#4C87FD" textFont:LGFontWeight(18, UIFontWeightSemibold) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}


-(UIButton *)messageBtn{
    if(!_messageBtn){
        _messageBtn = [UIButton buttonWithImage:@"咨询-更多" selectImage:@"咨询-更多"];
        [_messageBtn addTarget:self action:@selector(messageBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _messageBtn;
}

-(UIButton *)searchBtn{
    if(!_searchBtn){
        _searchBtn = [UIButton buttonWithImage:@"患者管理-搜索" selectImage:@"患者管理-搜索"];
        [_searchBtn addTarget:self action:@selector(searchBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _searchBtn;
}

-(UIImageView *)extendView{
    if(!_extendView){
        _extendView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"咨询-扩展"]];
        _extendView.userInteractionEnabled = YES;
        _extendView.hidden = YES;
        [_extendView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectExtendAction:)]];
    }
    return _extendView;
}

-(UIView *)cornerView{
    if(!_cornerView){
        _cornerView = [[UIView alloc] initWithFrame:CGRectMake(0, topBarHeight+viewPix(8), Screen_W, Screen_H-topBarHeight-tabBarHeight-viewPix(8))];
        CAGradientLayer *layer = [CAGradientLayer layer];
        layer.frame = CGRectMake(0,0,Screen_W,Screen_H-topBarHeight-tabBarHeight-viewPix(8));
        layer.startPoint = CGPointMake(0.5, 0);
        layer.endPoint = CGPointMake(0.5, 1);
        layer.colors = @[(__bridge id)[UIColor colorWithString:@"#FFFFFF" alpha:0.3].CGColor, (__bridge id)[UIColor colorWithString:@"#FFFFFF"].CGColor, (__bridge id)[UIColor colorWithString:@"#FFFFFF"].CGColor];
        layer.locations = @[@(0), @(0.6f), @(1.0f)];
        layer.borderColor = [UIColor colorWithString:@"#FFFFFF" alpha:0.5].CGColor;
        layer.borderWidth = 1.5;
        layer.cornerRadius = 15;
        [_cornerView.layer addSublayer:layer];
    }
    return _cornerView;
}

-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight-tabBarHeight-viewPix(8)) style:UITableViewStylePlain];
        [_tableView registerClass:[LGConsultHomeViewCell class] forCellReuseIdentifier:@"cell"];
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.rowHeight = viewPix(70);
        _tableView.cornerRidus = 15;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(10))];
        _tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(30))];
    }
    return _tableView;
}



-(LGSelectGroupChatView *)groupView{
    if(!_groupView){
        _groupView = [[LGSelectGroupChatView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H)];
        _groupView.delegate = self;
    }
    return _groupView;
}

-(LGBottomShadowView *)shadowView{
    if (!_shadowView) {
        _shadowView = [[LGBottomShadowView alloc]initWithFrame:CGRectMake(0, Screen_H-tabBarHeight-20, Screen_W, 20)];
    }
    return _shadowView ;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
